﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TeamFranceTriple
{
    [DefaultProperty("Title")]
    [ToolboxData("<{0}:YouTube runat=\"server\" Src=\"\" Title=\"\" />")]
    public class YouTube : WebControl
    {
        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        public String Title { get; set; }

        [Bindable(true)]
        [Category("Navigation")]
        [DefaultValue("")]
        public String Url { get; set; }

        [Bindable(true)]
        [Category("Layout")]
        [DefaultValue(0)]
        public new Int32 Width { get; set; }

        [Bindable(true)]
        [Category("Layout")]
        [DefaultValue(0)]
        public new Int32 Height { get; set; }

        [Bindable(true)]
        [Category("Layout")]
        [DefaultValue(0)]
        public Int32 FontSize { get; set; }

        protected override void Render(HtmlTextWriter output)
        { 
            String ContentBase;

            if (this.Width == 0 && this.Height == 0)
            {
                this.Width = 320;
                this.Height = 160;
            }

            if(this.FontSize==0)
                ContentBase = "<div class=\"panelMain\" style=\"width: " + (this.Width+20).ToString() +"px;\"><fieldset class=\"Youtube\"><legend>{0}</legend>" +
                    "<p class=\"centerP\"><iframe width=\"{2}\" height=\"{3}\" src=\"{1}\" frameborder=\"0\" allowfullscreen></iframe></p></fieldset></div>";
            else
            ContentBase = "<div class=\"panelMain\" style=\"width: " + (this.Width+20).ToString() +"px;\"><fieldset class=\"Youtube\"><legend><span style=\"font-size: {4}pt;\">{0}</span></legend>" +
                "<p class=\"centerP\"><iframe width=\"{2}\" height=\"{3}\" src=\"{1}\" frameborder=\"0\" allowfullscreen></iframe></p></fieldset></div>";

            output.Write(string.Format(ContentBase, this.Title, this.Url, this.Width.ToString(), this.Height.ToString(),this.FontSize.ToString()));
        }
    }
}
